package com.neu.controller;

import com.neu.bean.User;
import com.neu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
@RestController
public class UserController {

    @Autowired
    private UserService userService;

   @PostMapping(value="/user/login",produces ="application/json; charset=utf-8")
    public Map<String,String> getUser(@RequestBody User user){
        Map<String,String > retMap=new HashMap<>();

        User myUser=userService.getUser(user.getName());
        //用户名存在
        if(myUser!=null){
            //密码一样
            if(myUser.getPassword().equals(user.getPassword())){
                //返回json
                retMap.put("result","true");
                retMap.put("msg","成功");
                retMap.put("role","学生");
                return retMap;
            }
        }

        retMap.put("result","false");
        retMap.put("msg","失败");

        return retMap;
    }
}
